from sympy import series, sin, cos, exp, log, symbols

x = symbols('x')

# 泰勒级数展开
taylor_sin = series(sin(x), x, 0, 10)  # 在x=0处展开到10阶
print("sin(x)的泰勒展开:", taylor_sin)

taylor_exp = series(exp(x), x, 0, 5)   # 在x=0处展开到5阶
print("e^x的泰勒展开:", taylor_exp)

# 自定义函数的泰勒展开
def my_function(x):
    return sin(x) + cos(x) + log(abs(x) + 2)**2

# 使用series函数进行展开
taylor_custom = series(my_function(x), x, 0, 6)
print("自定义函数的泰勒展开:", taylor_custom)